import Core from '@/core.js'
import recom from '@/components/regionComponent'
export default {
  components: {
    recom
  },
  data() {
    return {
      Core,
      more: {
        name: '查看更多',
      },
      showTime: false, //时间picker
      timmer: '', //最后显示的时间
      proceduresShow: false, //手续弹窗
      proceduresList: ['随车', '7天出发', '15天内出发', '30天内出发'],
      proceduresName: '', //选择手续弹窗后页面显示
      detailShow: false, //车辆详情弹窗
      detailList: ['现车现票/不店保', '现车现票/店保', '质损车源', '期货/店保', '其他'],
      detailName: '', //选择车辆详情弹窗后页面显示
      zoneShow: false, //车辆所在地
      asktype: 0,
      findcarid: '',
      mobile: '',
      endtime: '',
      price: '',
      truename: '',
      Deposit: '',
      gettime: '',
      cardetail: '',
      address: '',
      contacts: '',
      successPoup: false, //完成弹窗默认隐藏
    }
  },
  onLoad(e) {
    this.findcarid = e.findid
    //默认读取用户自己的信息
    this.contacts = Core.CurrentUser().truename + ' ' + Core.CurrentUser().mobile
    uni.$on('contacts', data => {
      this.contacts = data
    })
  },
  methods: {
    //查看更多
    getMore() {
      if (this.more.name == '查看更多') {
        this.more.name = '收起'
      } else {
        this.more.name = '查看更多'
      }
    },
    // 打开时间选择器
    openTimePicker() {
      this.showTime = true
    },
    // 到期时间
    chooseTime(e) {
      this.endtime = e.year + '-' + e.month + '-' + e.day
    },
    //打开弹出层
    openPoup(type) {
      if (type == 0) { //手续弹出层
        this.proceduresShow = true
      } else if (type == 1) { // 汽车详情
        this.detailShow = true
      } else if (type == 2) { //车辆所在地
        this.zoneShow = true
      } else if (type == 3) { //跳转报价联系人页面
        uni.navigateTo({
          url: '/pages_dzr/R_contacts/R_contacts'
        })
      }
    },
    // 选择手续时间
    chooseProcedures(index) {
      this.proceduresShow = false
      this.gettime = index
      this.proceduresName = this.proceduresList[index]
    },
    // 选择汽车详情
    chooseDetail(index) {
      this.detailShow = false
      this.cardetail = index
      this.detailName = this.detailList[index]
    },
    //选择地区确定按钮
    confirmdz(e) {
      this.address = e.city.label
    },
    //选择地区取消按钮
    cancel() {
      this.zoneShow = false
    },
    // 提交完成报价
    sub() {
      const formdata = {
        asktype: this.asktype, // 0、寻车报价 1、新车询底价 2、配件询价 ,
        findcarid: this.findcarid, //寻车数据id ,
        mobile: this.mobile, // 电话号码 ,
        endtime: this.endtime, // 到期时间 ,
        price: this.price, // 报价价格 ,
        truename: this.truename, //报价联系人 ,
        Deposit: this.Deposit, //: 定金 ,
        gettime: this.gettime, //手续时间(0、随车 1、7天内 2、15天内 3、30天内) ,
        cardetail: this.cardetail, // 汽车详情 ,
        address: this.address, // (string): 车辆所在地 ,
        Tid: Core.CurrentUser().uid, // (string, optional): 登入人id
      }
      Core.AjaxPost(Core.Bus.askApiAddress, formdata, res => {
        this.successPoup = true
        uni.$off('contacts') //销毁
      })
    },
    //关闭提交成功的弹窗
    closPoupe() {
      this.successPoup = false
    }
  }
}
